
//app主页
/**
 * 进入系统的逻辑处理在这里
 * 比如判断有没有登录, 要不要强制登录
 * 是否是第一次打开APP, 如果是则打开引导页
 * PS: 如果要启用广告页, 则将openSplashScreen()取消注释即可
 */
import 'dart:async';

import 'package:moonplay/pages/splash_screen.dart';
import 'package:moonplay/provide/provide.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class AppHomePage extends StatefulWidget {
  @override
  _AppHomePageState createState() => _AppHomePageState();
}

class _AppHomePageState extends State<AppHomePage> {
  int isLogin = 1;
  OverlayEntry entry;

  @override
  void initState() {
    super.initState();
    _init();

    
  }

  Future _init() async {
    await Future.delayed(Duration(milliseconds: 0));
    if(isLogin == 1) {
      openSplashScreen();
      ///如果启用广告页, 则打开appIndexPage的时间延时500毫秒, 否则延时0即可
      await Future.delayed(Duration(milliseconds: 0));
      Get.toNamed('/AppIndexPage');
    }
  }

  openSplashScreen(){
    entry = OverlayEntry(builder: (context) {
      return SplashScreen(
        onTap: (){
          entry?.remove();
          entry = null;
        },
        onDoubleTap: (){
          entry?.remove();
          entry = null;
        },
      );
    });
    Overlay.of(context).insert(entry);
  }

  @override
  Widget build(BuildContext context) {
    //查询当前系统模式是否暗色主题,如果是则通知主题修改
    final Brightness brightnessValue = MediaQuery.of(context).platformBrightness;
    bool isDark = brightnessValue == Brightness.dark;
    if(isDark) {
      Provide.value<ThemeProvider>(context).setTheme(ThemeMode.dark);
    }
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Center(),
    );
  }
}